package com.wangzh.data.arithmetic.sort;

import java.util.Arrays;

public class A02_SelectionDemo {
    public static void main(String[] args) {
        //1.定义数组
        int[] arr = {5, 4, 1, 3, 1};

        //1. 从0索引开始，跟后面的元素一一比较
        //2. 小的放前面，大的放后面
        for (int i = 0; i < arr.length; i++) {
            for (int j = i+1; j < arr.length; j++) {
                if (arr[j]<arr[i]) {
                    int temp = arr[i];
                    arr[i]=arr[j];
                    arr[j]=temp;
                }
            }
        }

        System.out.println(Arrays.toString(arr));
    }
}
